package com.sooth.system.user.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.dream.system.config.Page;
import com.sooth.common.core.domain.R;
import com.sooth.common.dream.model.PageModel;
import com.sooth.common.log.annotation.Log;
import com.sooth.common.web.core.BaseController;
import com.sooth.system.user.service.ISysUserService;
import com.sooth.system.user.view.SysUserBo;
import com.sooth.system.user.view.SysUserDto;
import com.sooth.system.user.view.SysUserVo;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 用户信息
 *
 * @author Lion Li
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/user")
public class SysUserController extends BaseController {

    private final ISysUserService userService;

    /**
     * 获取用户列表
     */
    @SaCheckPermission("system:user:query")
    @GetMapping("/list")
    public R<Page<SysUserVo>> list(SysUserDto user, PageModel pageModel) {
        return R.ok(userService.queryPage(user, pageModel));
    }

    /**
     * 获取用户详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("system:user:query")
    @GetMapping("/query")
    public R<SysUserBo> query(@RequestParam Long id) {
        return R.ok(userService.selectById(id));
    }

    /**
     * 新增用户
     */
    @SaCheckPermission("system:user:add")
    @Log(title = "用户管理", message = "新增用户")
    @PostMapping("/add")
    public R<Void> add(@Validated @RequestBody SysUserBo user) {
        return toAjax(userService.insert(user));
    }

    /**
     * 修改用户
     */
    @SaCheckPermission("system:user:edit")
    @Log(title = "用户管理", message = "修改用户")
    @PutMapping("/edit")
    public R<Void> edit(@Validated @RequestBody SysUserBo user) {
        return toAjax(userService.updateById(user));
    }

    /**
     * 删除用户
     *
     * @param id 角色ID
     */
    @SaCheckPermission("system:user:remove")
    @Log(title = "用户管理", message = "删除用户")
    @DeleteMapping("/remove")
    public R<Void> remove(@RequestParam Long id) {
        return toAjax(userService.deleteById(id));
    }

//    /**
//     * 保存用户角色
//     * @param userRoleVo 用户角色
//     * @return
//     */
//    @Log(title = "用户角色管理")
//    @PostMapping("/role/save")
//    public R<Void> list(@RequestBody SysUserRoleVo userRoleVo) {
//        userRoleService.save(userRoleVo);
//        return R.ok();
//    }
}
